package cn.iocoder.yudao.module.member.vip.dal.mysql;

import cn.iocoder.yudao.framework.business.eligibility.dao.EligibilityUserMapper;
import cn.iocoder.yudao.module.api.member.vip.vo.VipUserSummaryVO;
import cn.iocoder.yudao.module.member.vip.dal.dataobject.VipUserDO;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

/**
 * 会员 Mapper
 *
 * @author 山野羡民
 */
@Mapper
public interface VipUserMapper extends EligibilityUserMapper<VipUserDO> {

    @Select("""
            SELECT IFNULL(SUM(IF(`type` = 1 AND expire_time > NOW(), 1, 0)), 0) AS valid_count, IFNULL(SUM(IF(expire_time <= NOW(), 1, 0)), 0) AS invalid_count
            FROM member_vip_user
            WHERE deleted = FALSE AND bind_shop_id = #{shopId}
            """)
    VipUserSummaryVO selectVipSummaryByBindShopId(@Param("shopId") Long shopId);

}